#include <QEvent>

#include "INCLUDE/BmpChild.h"
#include "../JWTS/INCLUDE/WINDOWSEVENT.HPP"

BmpChild::BmpChild(const char *p_name, const QImage *imFILE, QWidget* parent) :
    QGraphicsView(parent),
    MdiChild(p_name)
{
    QPixmap pixmap = QPixmap::fromImage(*imFILE);

    // Create a QGraphicsScene
    auto scene = new QGraphicsScene(this);

    // Add QPixmap to the scene as a QGraphicsPixmapItem
    scene->addPixmap(pixmap);

    setScene(scene);

    setSceneRect(pixmap.rect());

    setAttribute(Qt::WA_DeleteOnClose);
}

bool BmpChild::event(QEvent *event)
{
    if ((event != nullptr) && (event->type() > QEvent::Type::User))
    {
        auto pWindowsEvent = dynamic_cast<WindowsEvent*>(event);
        if (pWindowsEvent != nullptr)
        {
            switch (pWindowsEvent->Msg())
            {
            default:
                break;
            }
            return true;
        }
    }
    return QGraphicsView::event(event);
}


void BmpChild::closeEvent(QCloseEvent *event)
{
    emit pSignalEmitter()->aboutToClose(this);

    QGraphicsView::closeEvent(event);
}
